﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using tracker.Models.BLL;
using tracker.Models;
using System.Data;
using tracker.Models.DTO;

namespace tracker.Controllers
{
    public class HandlerGetStateDefineInfoController : Controller
    {
       /// <summary>
       /// Get All Alarm Define
       /// </summary>
       /// <returns></returns>
        [CallAjaxFilter]
        public JsonStringResult Index()
        {

            string result = "";
            string _username = HttpContext.Session[Common.USER].ToString();
            string _language = HttpContext.Session[Common.LANGUAGE].ToString();
            _language = _language == string.Empty ? "vi" : _language;

            DataTable dt = StatusDefineBLL.SelectAll(new string[] { EStatusDefine.FIED_CREATEBY }, new object[] { _username }).Tables[0];
            List<EStatusDefine> list = new List<EStatusDefine>();

            foreach (DataRow item in dt.Rows)
            {
                EStatusDefine ent = new EStatusDefine();
                ent.true_exp = item["true_exp"].ToString();
                ent.false_exp = item["false_exp"].ToString();
                ent.Expression = item["Expression"].ToString();
                ent.BitIndex = ListDefineStatus.getName(item["BitIndex"].ToString(), _language);
                ent.DefineID = item["id"].ToString();
                list.Add(ent);
            }

            dt.Dispose();
            if (list.Count > 0)
            {
                result = Utilities.getJsonString(list,"data:", 1);
            }
            else
                result = "{[]}";

            return new JsonStringResult(result);
        }
    }
}
